export default {
    data() {
        return {
            setIconFlag: false
        };
    },

    created() {
        this.setWebIcon();
    },

    methods: {
        setWebIcon() {
            const iconEnv = process.env.VUE_APP_WEB_ICON == 'true';

            const iconName = '/favicon.ico';

            const currentTimeStamp = new Date().getTime().toString();

            if (iconEnv && !this.setIconFlag) {
                const head = document.head;

                let linkElement = head.querySelector("link[rel*='icon']");

                if (linkElement) {
                    linkElement.href = `${iconName}?_t=${currentTimeStamp}`;
                } else {
                    linkElement = document.createElement('link');
                    linkElement.type = 'image/x-icon';
                    linkElement.rel = 'shortcut icon';
                    linkElement.href = `${iconName}?_t=${currentTimeStamp}`;
                    head.appendChild(linkElement);
                }

                this.setIconFlag = true;
            }
        }
    }
};
